﻿using Sys.Common;
using Sys.Core.Sys;
using Sys.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sys.Api.Sys
{
    public class DicTypeApi : BaseApi
    {
        public string Grid()
        {
            var entities = DicTypeBll.I.SortEntities;

            return JsonHelper.ToJson(entities.ToList());
        }

        public string Save(SysDicType model)
        {
            JsonMsg result = new JsonMsg();

            if (string.IsNullOrEmpty(model.ID))
            {
                result.Message = "添加成功!";

                model.ID = StringHelper.GetGuid();

                result.Success = DicTypeBll.I.Insert(model) > 0;
            }
            else
            {
                result.Message = "修改成功!";

                result.Success = DicTypeBll.I.Update(model) > 0;
            }

            if (!result.Success) { result.Message = "操作失败!"; }

            return JsonHelper.ToJson(result);
        }

        public string Delete(string id)
        {
            JsonMsg result = new JsonMsg();

            result.Success = DicTypeBll.I.Delete(id) > 0;

            if (result.Success) { result.Message = "删除成功!"; }

            return JsonHelper.ToJson(result);
        }
    }
}
